package com.yfp.client.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfp.client.domain.MallOrder;
import com.yfp.client.domain.MallOrderDetails;
import com.yfp.client.domain.MallProduct;
import com.yfp.client.mapper.MallProductMapper;
import com.yfp.client.service.MallOrderDetailsService;
import com.yfp.client.service.MallProductService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * @description 针对表【mall_product(商城商品表)】的数据库操作Service实现
 * @createDate 2025-03-05 10:54:48
 */
@Service
@Slf4j
public class MallProductServiceImpl extends ServiceImpl<MallProductMapper, MallProduct> implements MallProductService {

    @Resource
    private MallProductMapper mallProductMapper;
    @Resource
    private MallOrderDetailsService mallOrderDetailsService;

    @Override
    public List<MallProduct> getList(MallProduct mallProduct) {
        return mallProductMapper.getList(mallProduct);
    }

    @Override
    public MallProduct findInfoById(Long id) {
        return mallProductMapper.getById(id);
    }

    @Override
    public void decreaseStockQuantity(Long id) {
        mallProductMapper.decreaseStockQuantity(id);
    }

    @Override
    public void recoverStockQuantity(MallOrder mallOrder) {
        List<MallOrderDetails> mallOrderDetails = mallOrderDetailsService.listByMallOrderId(mallOrder.getId());
        for (MallOrderDetails mallOrderDetail : mallOrderDetails) {
            mallProductMapper.recoverStockQuantity(mallOrderDetail.getMallProductId());
        }
    }
}
